﻿package labox.innovation.gameserver.model.actor.appearance;

import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.model.base.Sex;
import labox.innovation.gameserver.model.itemcontainer.Inventory;
import labox.innovation.gameserver.network.serverpackets.StatusUpdate;

/**
 * 玩家角色外形控制类
 * 
 * @author Administrator
 * 
 */
public final class PcAppearance {
	// =========================================================
	// Data Field
	/**
	 * 外形的所有对象
	 */
	private FuzePcInstance _owner;

	/**
	 * 外形的性别枚举
	 */
	private Sex _sex;

	/**
	 * 对象是否隐形
	 */
	private boolean _invisible;

	/**
	 * 对象当前的显示名称
	 */
	private String _visibleName;

	/**
	 * 对象当前的显示头衔
	 */
	private String _visibleTitle;

	/**
	 * 对象当前的名字颜色
	 */
	private int _nameColor = 0xFFFFFF;

	/**
	 * 对象当前的头衔颜色
	 */
	private int _titleColor = 0xFFFF77;

	private int _paperdoll;

	private int _animationID = -1;

	// =========================================================
	// Constructor
	public PcAppearance(int sex) {
		_sex = Sex.getSex(sex);
	}

	/**
	 * 设置显示的名称
	 * 
	 * @param visibleName
	 *            The visibleName to set.
	 */
	public final void setVisibleName(String visibleName) {
		_visibleName = visibleName;
	}

	/**
	 * 返回显示的名称
	 * 
	 * @return Returns the visibleName.
	 */
	public final String getVisibleName() {
		if (_visibleName == null) {
			_visibleName = getOwner().getName();
		}
		return _visibleName;
	}

	/**
	 * 设置显示的头衔
	 * 
	 * @param visibleTitle
	 *            The visibleTitle to set.
	 */
	public final void setVisibleTitle(String visibleTitle) {
		_visibleTitle = visibleTitle;
	}

	/**
	 * 返回显示的头衔
	 * 
	 * @return Returns the visibleTitle.
	 */
	public final String getVisibleTitle() {
		if (_visibleTitle == null) {
			_visibleTitle = getOwner().getTitle();
		}
		return _visibleTitle;
	}

	/**
	 * 返回玩家的性别
	 * 
	 * @return
	 */
	public final Sex getSex() {
		return _sex;
	}

	/**
	 * 设置玩家的性别
	 */
	public final void setSex(int sex) {
		_sex = Sex.getSex(sex);
	}

	/**
	 * 设置隐身
	 */
	public void setInvisible() {
		_invisible = true;
	}

	/**
	 * 设置可见
	 */
	public void setVisible() {
		_invisible = false;
	}

	/**
	 * 返回是否隐身
	 * 
	 * @return
	 */
	public boolean getInvisible() {
		return _invisible;
	}

	/**
	 * 获得名字的颜色
	 * 
	 * @return
	 */
	public int getNameColor() {
		return _nameColor;
	}

	/**
	 * 设置名字的颜色
	 * 
	 * @param nameColor
	 */
	public void setNameColor(int nameColor) {
		_nameColor = nameColor;
	}

	/**
	 * 设置名字的颜色
	 * 
	 * @param red
	 * @param green
	 * @param blue
	 */
	public void setNameColor(int red, int green, int blue) {
		_nameColor = (red & 0xFF) + ((green & 0xFF) << 8) + ((blue & 0xFF) << 16);
	}

	/**
	 * 获得头衔的颜色
	 * 
	 * @return
	 */
	public int getTitleColor() {
		return _titleColor;
	}

	/**
	 * 设置头衔的颜色
	 * 
	 * @param titleColor
	 */
	public void setTitleColor(int titleColor) {
		_titleColor = titleColor;
	}

	/**
	 * 设置头衔的颜色
	 * 
	 * @param red
	 * @param green
	 * @param blue
	 */
	public void setTitleColor(int red, int green, int blue) {
		_titleColor = (red & 0xFF) + ((green & 0xFF) << 8) + ((blue & 0xFF) << 16);
	}

	/**
	 * 
	 * 设置外形对象的所有者
	 * 
	 * @param owner
	 *            The owner to set.
	 */
	public void setOwner(FuzePcInstance owner) {
		_owner = owner;
	}

	/**
	 * 返回外形对象的所有者
	 * 
	 * @return Returns the owner.
	 */
	public FuzePcInstance getOwner() {
		return _owner;
	}

	public int getAnimationID() {
		if (_animationID < 0)
			_animationID = _owner.getTemplate().get_animationId();
		return _animationID;
	}

	public void setAnimationID(int ani) {
		_animationID = ani;
	}

	public void setPaperdoll(int paperdollID, int id) {
		int old = _paperdoll;
		switch (paperdollID) {
		case Inventory.PAPERDOLL_SHOULDER:
			_paperdoll &= 0xfffffff0;
			_paperdoll |= id;
			break;
		case Inventory.PAPERDOLL_CHEST:
			_paperdoll &= 0xffffff0f;
			_paperdoll |= id << 4;
			break;
		case Inventory.PAPERDOLL_HAND:
			_paperdoll &= 0xfffff0ff;
			_paperdoll |= id << 8;
			break;
		case Inventory.PAPERDOLL_LEGS:
			_paperdoll &= 0xffff0fff;
			_paperdoll |= id << 12;
			break;
		}
		if (old != _paperdoll) {
			StatusUpdate su = new StatusUpdate(_owner.getObjectId());
			su.addAttribute(StatusUpdate.PAPERDOLL, _paperdoll);
			_owner.sendPacket(su);
		}
	}

	public int getPaperDoll() {
		return _paperdoll;
	}

	public void setPaperDoll(int paperdoll) {
		_paperdoll = paperdoll;
	}
}
